var fieldtypeData = [		
	{
		fieldtype : "varchar",
		text : "varchar"
	}, {
		fieldtype : "date",
		text : "date"
	}, {
		fieldtype : "datetime",
		text : "datetime"
	}, {
		fieldtype : "numeric",
		text : "numeric"
	}, {
		fieldtype : "int",
		text : "int"
	}, { 
		fieldtype: "bigint", 
		text: 'bigint' 
	}, { 
		fieldtype: "binary", 
		text: 'binary'
	}, {
		fieldtype : "bit",
		text : "bit"
	}, {
		fieldtype : "blob",
		text : "blob"
	}, {
		fieldtype : "bool",
		text : "bool"
	}, {
		fieldtype : "boolean",
		text : "boolean"
	}, {
		fieldtype : "char",
		text : "char"
	}, {
		fieldtype : "decimal",
		text : "decimal"
	}, {
		fieldtype : "double",
		text : "double"
	}, {
		fieldtype : "enum",
		text : "enum"
	}, {
		fieldtype : "float",
		text : "float"
	}, {
		fieldtype : "longblob",
		text : "longblob"
	}, {
		fieldtype : "longtext",
		text : "longtext"
	} , {
		fieldtype : "mediumblob",
		text : "mediumblob"
	} , {
		fieldtype : "mediumint",
		text : "mediumint"
	} , {
		fieldtype : "mediumtext",
		text : "mediumtext"
	}  , {
		fieldtype : "real",
		text : "real"
	} , {
		fieldtype : "set",
		text : "set"
	} , {
		fieldtype : "smallint",
		text : "smallint"
	} , {
		fieldtype : "text",
		text : "text"
	} , {
		fieldtype : "time",
		text : "time"
	} , {
		fieldtype : "timestamp",
		text : "timestamp"
	} , {
		fieldtype : "tinyblob",
		text : "tinyblob"
	} , {
		fieldtype : "tinyint",
		text : "tinyint"
	} , {
		fieldtype : "tinytext",
		text : "tinytext"
	} , {
		fieldtype : "varbinary",
		text : "varbinary"
	} , {
		fieldtype : "year",
		text : "year"
	}
];
var ismustData = [{ ismust: 1, text: '是' }, { ismust: 0, text: '否'}];
var iskeyData = [{ iskey: 1, text: '是' }, { iskey: 0, text: '否'}];


// Column Renders For Liger DataGrid 
function f_renderSex(rowdata, index, value){
	if(value=='1'){
		return '先生';
	}else{
		return '女士';
	}
}
//

/**CREATE TABLE `test` (
		  `field1` bigint(1) unsigned zerofill NOT NULL DEFAULT '1' COMMENT '备注',
		  `field2` binary(2) NOT NULL DEFAULT '2\0' COMMENT '备注2',
		  PRIMARY KEY (`field1`,`field2`)
		) ENGINE=InnoDB DEFAULT CHARSET=utf8**/
var nolenField="[bool][boolean][date][datetime][longblob][longtext][mediumblob][mediumtext][time][tinyblob][tinytext]";
function createSql(tableName, columns){
	var sql = "CREATE TABLE " + tableName +" ( \r\n";
	var primaryKey = " PRIMARY KEY (";
	for(var i=0;i < columns.length;i++){
		sql+=" "+columns[i].fieldid+" ";
		if(nolenField.indexOf("[" + columns[i].fieldtype+"]") < 0){
			sql+=columns[i].fieldtype+"("+columns[i]. fieldlength+") ";
		}else{
			sql+=columns[i].fieldtype+" ";
		} 
		// DEFAUL VALUE
		if(columns[i].defaultvalue != ""){
			sql+=" DEFAULT '"+ columns[i].defaultvalue+"' ";
		}
		// 非空
		if(columns[i].ismust == 1){
			sql+=" NOT NULL ";
		}
		sql+=" COMMENT '"+columns[i].remark+"', ";
		if(columns[i].iskey == 1){
			primaryKey+=" "+columns[i].fieldid+",";
		}
		sql+="\r\n"
	}	
	if(primaryKey.indexOf(",") >0){// 有主键
		primaryKey = primaryKey.substring(0,primaryKey.length-1) + ") ";
	}else {
		primaryKey="";
	}
	sql+=primaryKey + "\r\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;";
	 var dropSql = "";
	if($("#chk1").attr("checked") == true){
		 dropSql="DROP TABLE " + tableName+"; \r\n";
	}
	return dropSql + sql;
}
// advanced query
function advancedQuery(tablename){
	var url="/advancedQuery?tablename="+tablename;
	$.ligerDialog.open({ url: url, height: 500,width: 500,
		title:"高级查询"});
}
// function validate
function validateForm(){// 这里是使用了EasyValidator专用的验证	
	return $(".input_validation-failed").length === 0;
}


